using System;
using XDQ.VAT.Permissions;
using XDQ.VAT.Courses.Dtos;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using System.Linq;

namespace XDQ.VAT.Courses
{
    public class AppCourseAppService : CrudAppService<AppCourse, AppCourseDto, Guid, PagedAndSortedResultRequestDto, CreateUpdateAppCourseDto, CreateUpdateAppCourseDto>,
        IAppCourseAppService
    {
        protected override string GetPolicyName { get; set; } = VATPermissions.AppCourse.Default;
        protected override string GetListPolicyName { get; set; } = VATPermissions.AppCourse.Default;
        protected override string CreatePolicyName { get; set; } = VATPermissions.AppCourse.Create;
        protected override string UpdatePolicyName { get; set; } = VATPermissions.AppCourse.Update;
        protected override string DeletePolicyName { get; set; } = VATPermissions.AppCourse.Delete;

        private readonly IAppCourseRepository _repository;

        public AppCourseAppService(IAppCourseRepository repository) : base(repository)
        {
            _repository = repository;
        }

        protected override IQueryable<AppCourse> ApplySorting(IQueryable<AppCourse> query, PagedAndSortedResultRequestDto input)
        {
            if (string.IsNullOrEmpty(input.Sorting))
            {
                input.Sorting = "sort asc";
            }
            return base.ApplySorting(query, input);
        }
    }
}
